<?php
/***************
* @Project	Warabi
* @Author	Feifei
* @Date		04/10/2009
***************/

/**This module is to deal the ap modify the language**/
include_once($_SERVER['DOCUMENT_ROOT'].'/header.inc.php');

$httprequest = new wbHttpRequest();

list($headers , $body) = $httprequest->output();
$sender_name= rawurldecode($_GET["sender"]);


/**if new language is empty, give a 403 response**/
$xml = simplexml_load_string($body);
if(!$xml){
	header(error_xml_structure);
	exit;
}
$lang = strval($xml->lang);
if(empty($lang)){
	#header(error_xml_element_missing);
	header(success_response);
	exit;
}

/**if the sender is empty , give a 400 response**/
if(empty($sender_name)){
	header(error_url_param_missing);
	exit;
}

/**if the sender doesn't exist in database , give a 400 response**/
$db = new wbDatabase();
$sql = "select * from ".__table_app_user__." where username='".$sender_name."'";
$set = $db->query($sql);

if($db->countResult($set)==0){
	header(error_url_param_missing);
	exit;
}

$db->freeResult($set);

/** wsse authorize **/
/***if the wsse is wrong , give a 401 unauthorized response**/
$xwsse = $headers["X_WSSE"];
$type=0;
$doorkey = magicWsse($xwsse , $db , $type);

if(!$doorkey){
	header(error_autorized_header);
	exit;
}

$sql = "update ".__table_app_user__." set language='".$lang."' where username='".$sender_name."'";
$err = $db->query($sql);
$db->disconnect();
if(!$err){
	header(error_server_system);
	exit;
}


/***put the response to the client**/
header(success_response);


?>



